package com.bbcare.followup.plat.task;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.StringUtils;

import java.math.BigInteger;
import java.util.Comparator;
import java.util.HashMap;

/**
 * 随访任务排序比较器，区别计划随访和临时随访。
 */
public class QuestionsComparator implements Comparator<Object> {
    @Override
    public int compare(Object obj1, Object obj2) {
        if (!(obj1 instanceof JSONArray) || !(obj2 instanceof JSONArray))   {
            return -1;
        }
        JSONArray question1   = (JSONArray)obj1;
        JSONArray question2   = (JSONArray)obj2;

        JSONObject jsonObject1 = question1.getJSONObject(0);
        JSONObject jsonObject2 = question2.getJSONObject(0);

        Integer rowNumber1 = Integer.parseInt(jsonObject1.get("label").toString().substring(jsonObject1.get("label").toString().lastIndexOf("_") + 1));;
        Integer rowNumber2 = Integer.parseInt(jsonObject2.get("label").toString().substring(jsonObject2.get("label").toString().lastIndexOf("_") + 1));;

        if (0 == rowNumber1)    {
            return 1;
        }
        if (0 == rowNumber2)    {
            return -1;
        }
        if (null != rowNumber1 && null != rowNumber2)   {
            return rowNumber2.compareTo(rowNumber1);
        } else {
            return 0;
        }

    }
}
